import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button } from 'antd';
import styles from './../Users.css';
import moment from 'moment';
import Factory from '../../factory';
import * as datetime from '../../../utils/datetime'
import dataEditCreate from '../../addons/DataEdit'
import dataTableCreate from '../../addons/DataTable'
const daoName = "CompPaySalaryCorpFhqk";
const ButtonGroup = Button.Group;
const columns = [
    { title: '员工编号', dataIndex: 'EMNO', key: 'EMNO', width: 100, sorter: true, dispaly: true, filter: true },
    { title: '员工名称', width: 100, sorter: true, dataIndex: 'SysUserName', key: 'SysUserName', dispaly: true, filter: true },
    { title: '开户机构', width: 100, sorter: true, dataIndex: 'OrganName', key: 'OrganName', dispaly: true, filter: true },
    { title: '分户日期', width: 100, sorter: true, key: 'DSDT', caption: "DSDT", render: data => datetime.format(data.DSDT, "yyyy-MM-dd"), dispaly: true, filter: true, canEdit: true },
    { title: '终止日期', width: 100, sorter: true, key: 'WODT', caption: "WODT", render: data => datetime.format(data.WODT, "yyyy-MM-dd"), dispaly: true, filter: true, canEdit: true },
    { title: '分户值(%)', width: 100, sorter: true, dataIndex: 'DSVL', key: 'DSVL', dispaly: true, filter: true, canEdit: true, render: data => data * 100 },
];
const controls = [
    { name: 'EMNO', required: true, type: 'alphanum', label: '员工编号', grid: 12 / 24 },
    { name: 'SysUserName', required: true, type: 'text', label: '员工名称', grid: 12 / 24 },
    { name: 'OrganName', required: true, type: 'text', label: '开户机构', grid: 12 / 24 },
    { name: "DSDT", label: "分户日期", type: "date", grid: 12 / 24, dataType: "date" },
    { name: "WODT", label: "终止日期", type: "date", grid: 12 / 24, dataType: "date" },
    { name: "DSVL", label: '分户值', type: "number", grid: 12 / 24, dataType: "number" },
]
const EditFrom = dataEditCreate(daoName);
const DataTable = dataTableCreate(daoName);
class Comp_PaySalaryCorpFhqk extends Component {
    constructor(props) {
        super(props);
        this.state = {
            dataChange: false
        };
    }
    componentDidMount() {
        this.props.dispatch({
            type: `${daoName}/setKeyName`,
            payload: { keyName: "ID" }
        });
        this.loadOptionData();
    }
    componentWillReceiveProps(nextProps) {
        const l1 = nextProps.masterSelectedRowKeys.length
        const l2 = this.props.masterSelectedRowKeys.length
        let k1 = -1
        let k2 = -1
        if (l1 > 0) {
            k1 = nextProps.masterSelectedRowKeys[l1 - 1]
        }
        if (l2 > 0) {
            k2 = this.props.masterSelectedRowKeys[l2 - 1]
        }
        if (k1 !== k2) {
            let seeks = [];
            let whereItems = [];
            let WhereCauses = [];
            whereItems.push({
                FieldName: "CUID",
                Operator: "=",
                FieldValues: '' + k1
            })
            WhereCauses.push({
                WhereItems: whereItems,
                RelationSign: "AND"
            })
            seeks = WhereCauses;
            this.props.dispatch({
                type: `${daoName}/fetch`,
                payload: { daoName, page: 1, pageSize: 20, seeks }
            });
        }
    }
    loadOptionData() {
        let options = []
        controls.map(c => {
            if (c.fetch) {
                let f = c.fetch;
                if (c.type === 'cascader-select') {
                    f.isCascader = true;
                }
                if (c.type !== 'search') {
                    options.push(f);
                }
            }
        })
        if (daoName && options.length > 0) {
            this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
        }
    }
    render() {
        let { showEdit, record, offsetHeight, masterSelectedRowKeys } = this.props
        let table2Height = (offsetHeight - 133) * 0.5 - 70
        return (
            <div className={styles.normal} style={{ background: '#fff', marginTop: -10, padding: '5px 5px' }}>
                <div>
                    <div className={styles.create}>
                    </div>
                    <DataTable ref="userTable" daoName={daoName} columns={columns} controls={controls} height={table2Height} canExport={false} />
                </div>
            </div>
        )
    }
}

function mapStateToProps(state) {
    const { showEdit, record, selectedRowKeys, keyName } = state[daoName];
    const masterSelectedRowKeys = state['CompPaySalaryCorp'].selectedRowKeys;
    const { offsetHeight } = state.menus
    return {
        showEdit,
        selectedRowKeys,
        keyName,
        record,
        offsetHeight,
        masterSelectedRowKeys
    }
}
Comp_PaySalaryCorpFhqk = connect(mapStateToProps)(Comp_PaySalaryCorpFhqk)
export default Comp_PaySalaryCorpFhqk;

let render = (props) => React.createElement(Comp_PaySalaryCorpFhqk, props);
let f = new Factory()
f.set("Comp_PaySalaryCorpFhqk", render)

